package com.yh.csx.bsf.flow.dao.dal.auto;

import java.util.ArrayList;
import java.util.Map;
import java.util.List;

import com.yh.csx.bsf.flow.core.db.ConvertUtil;
import com.yh.csx.bsf.flow.core.db.DbConn;
import com.yh.csx.bsf.flow.dao.model.auto.*;

/** 代码自动生成工具自动生成,不要在这里写自己的代码，否则会被自动覆盖哦 - 车毅*/
public class t_task_base_dal
{
    public boolean add(DbConn conn, t_task_model model)
    {
		Object[] Par = new Object[]{
		
		//
		model.flow_id,
		//
		model.flow_title,
		//
		model.flow_approve_node,
		//
		model.flow_approve_userno,
		//
		model.flow_approve_by,
		//
		model.next_userno,
		//
		model.task_state,
		//
		model.update_time,
		//
		model.update_by,
		//
		model.create_time,
		//
		model.create_by,
		//
		model.timeout,
		//
		model.timeout_time,
		//
		model.task_result,
		//
		model.batch_id
		};
        int rev = conn.executeSql("insert into t_task(flow_id,flow_title,flow_approve_node,flow_approve_userno,flow_approve_by,next_userno,task_state,update_time,update_by,create_time,create_by,timeout,timeout_time,task_result,batch_id)"+
										"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Par);
        return rev == 1;

    }

    public boolean edit(DbConn conn, t_task_model model)
    {
        ArrayList<Object> Par = new ArrayList<Object>();
        
		//
		Par.add(model.flow_id);
		//
		Par.add(model.flow_title);
		//
		Par.add(model.flow_approve_node);
		//
		Par.add(model.flow_approve_userno);
		//
		Par.add(model.flow_approve_by);
		//
		Par.add(model.next_userno);
		//
		Par.add(model.task_state);
		//
		Par.add(model.update_time);
		//
		Par.add(model.update_by);
		//
		Par.add(model.create_time);
		//
		Par.add(model.create_by);
		//
		Par.add(model.timeout);
		//
		Par.add(model.timeout_time);
		//
		Par.add(model.task_result);
		//
		Par.add(model.batch_id);
		Par.add(model.id);

        int rev = conn.executeSql("update t_task set flow_id=?,flow_title=?,flow_approve_node=?,flow_approve_userno=?,flow_approve_by=?,next_userno=?,task_state=?,update_time=?,update_by=?,create_time=?,create_by=?,timeout=?,timeout_time=?,task_result=?,batch_id=? where id=?",  Par.toArray());
        return rev == 1;

    }

    public boolean delete(DbConn conn, int id)
    {
        ArrayList<Object> Par = new ArrayList<Object>();
        Par.add(id);

        String Sql = "delete from t_task where id=?";
        int rev = conn.executeSql(Sql, Par.toArray());
        if (rev == 1)
        {
            return true;
        }
        else
        {
            return false;
        }

    }

    public t_task_model get(DbConn conn, int id)
    {
        ArrayList<Object> Par = new ArrayList<Object>();
        Par.add(id);
        StringBuilder stringSql = new StringBuilder();
        stringSql.append("select s.* from t_task s where s.id=?");
        List<Map<String,Object>> ds = conn.executeList(stringSql.toString(), Par.toArray());
        if (ds != null && ds.size() > 0)
        {
			return createModel(ds.get(0));
        }
        return null;
    }

	public ArrayList<t_task_model> list(DbConn conn)
    {
		ArrayList<t_task_model> rs = new ArrayList<t_task_model>();
        StringBuilder stringSql = new StringBuilder();
        stringSql.append("select s.* from t_task s ");
        List<Map<String,Object>> ds = conn.executeList(stringSql.toString(), new Object[]{});
        if (ds != null && ds.size() > 0)
        {
			for (Map<String,Object> dr : ds)
			{
				rs.add(createModel(dr));
			}
        }
        return rs;
    }

	public t_task_model createModel(Map<String,Object> dr)
    {
        t_task_model o = new t_task_model();
		
		//
		if(dr.containsKey("id"))
		{
			o.id = ConvertUtil.objToInt(dr.get("id"));
		}
		//
		if(dr.containsKey("flow_id"))
		{
			o.flow_id = ConvertUtil.objToInt(dr.get("flow_id"));
		}
		//
		if(dr.containsKey("flow_title"))
		{
			o.flow_title = ConvertUtil.objToStr(dr.get("flow_title"));
		}
		//
		if(dr.containsKey("flow_approve_node"))
		{
			o.flow_approve_node = ConvertUtil.objToStr(dr.get("flow_approve_node"));
		}
		//
		if(dr.containsKey("flow_approve_userno"))
		{
			o.flow_approve_userno = ConvertUtil.objToStr(dr.get("flow_approve_userno"));
		}
		//
		if(dr.containsKey("flow_approve_by"))
		{
			o.flow_approve_by = ConvertUtil.objToStr(dr.get("flow_approve_by"));
		}
		//
		if(dr.containsKey("next_userno"))
		{
			o.next_userno = ConvertUtil.objToStr(dr.get("next_userno"));
		}
		//
		if(dr.containsKey("task_state"))
		{
			o.task_state = ConvertUtil.objToByte(dr.get("task_state"));
		}
		//
		if(dr.containsKey("update_time"))
		{
			o.update_time = ConvertUtil.objToDateTime(dr.get("update_time"));
		}
		//
		if(dr.containsKey("update_by"))
		{
			o.update_by = ConvertUtil.objToStr(dr.get("update_by"));
		}
		//
		if(dr.containsKey("create_time"))
		{
			o.create_time = ConvertUtil.objToDateTime(dr.get("create_time"));
		}
		//
		if(dr.containsKey("create_by"))
		{
			o.create_by = ConvertUtil.objToStr(dr.get("create_by"));
		}
		//
		if(dr.containsKey("timeout"))
		{
			o.timeout = ConvertUtil.objToInt(dr.get("timeout"));
		}
		//
		if(dr.containsKey("timeout_time"))
		{
			o.timeout_time = ConvertUtil.objToDateTime(dr.get("timeout_time"));
		}
		//
		if(dr.containsKey("task_result"))
		{
			o.task_result = ConvertUtil.objToStr(dr.get("task_result"));
		}
		//
		if(dr.containsKey("batch_id"))
		{
			o.batch_id = ConvertUtil.objToInt64(dr.get("batch_id"));
		}
		return o;
    }
}
